package com.example.edu.Mapper;

import com.example.edu.Dto.Course_TimeDto;
import com.example.edu.Dto.TimeListDto;
import com.example.edu.Dto.TimeWordsDtoR;
import com.example.edu.Dto.WordsListDto;
import com.example.edu.Entity.Course_Record;
import com.example.edu.Entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface Course_RecordMapper {
    void add(@Param("course_id") int course_id, @Param("id") int id,@Param("days") List<Integer> days);

    @Delete("delete from course_record where course_id = #{course_id} and student_id = #{student_id}")
    void delete(@Param("course_id") int course_id, @Param("student_id") int id);

    void addMany(@Param("course_id") int course_id, @Param("ids") List<User> ids,@Param("days") List<Integer> days);

    void deleteMany(@Param("course_id") int course_id, @Param("ids") List<User> ids);

    @Update("update course_record set words = words + #{length} where course_id = #{course_id} and student_id = #{id} and day = #{day}")
    void addWords(@Param("course_id") int course_id, @Param("id") int id, @Param("day") int day, @Param("length") int length);

    @Update("update course_record set learn_time = learn_time + #{time} where course_id = #{course_id} and student_id = #{id} and day = #{day}")
    void addTime(@Param("course_id") int course_id, @Param("id") int id, @Param("day") int day, @Param("time") double time);

    @Select("select day,sum(words) as s_words,sum(learn_time) as s_time from course_record where course_id = #{course_id} group by day order by day")
    List<TimeWordsDtoR> getSituations(@Param("course_id") int course_id);

    @Select("select day,sum(words) as s_words,sum(learn_time) as s_time from course_course_record where course_teacher = #{id} group by day order by day")
    List<TimeWordsDtoR> getSituations2(@Param("id") int id);

    @Select("select day,sum(words) as s_words,sum(learn_time) as s_time from course_record where course_id = #{course_id} and student_id = #{id} group by day order by day")
    List<TimeWordsDtoR> getSituations3(@Param("course_id") int course_id, @Param("id") int id);

    @Select("select day,sum(words) as s_words,sum(learn_time) as s_time from course_student_course_record where student_id = #{id} group by day order by day")
    List<TimeWordsDtoR> getSituations4(@Param("id") int id);

    @Select("select student_id,nickname,learn_time from course_record_user where course_id = #{course_id} order by learn_time desc")
    List<TimeListDto> getTimeList(@Param("course_id") int course_id);

    @Select("select student_id,nickname,words from course_record_user where course_id = #{course_id} order by words desc")
    List<WordsListDto> getWordsList(@Param("course_id") int course_id);

    @Select("select course_id,course_name,sum(learn_time) as s_time from course_course_record where course_teacher = #{id} group by course_id,course_name order by course_id")
    List<Course_TimeDto> getLearnTime(@Param("id") int id);

    @Select("select course_id,course_name,sum(learn_time) as s_time from c_stu_c_course_record where student_id = #{id} group by course_id,course_name order by course_id")
    List<Course_TimeDto> getLearnTime2(@Param("id") int id);
}
